<?php
//error_reporting(0);
include("../connection/connection.php");
include("reportFunctions.php");
$distId=$_REQUEST['distId'];
$sqlReport = "SELECT distinct `district_id`,`district_name`,`block_id`,`block_name` FROM `tbl_lookup_location` where `district_id` = ".$distId." group by `block_id`";
$queryReport = mysql_query($sqlReport);

function getDesignPopWater($hp,$distId,$blockId) {
$sqlgetSchemeNoDistWise="SELECT sum($hp) FROM tbl_dtls_q2_main where district_id=".$distId." and block_id=".$blockId;
$querygetSchemeNoDistWise=mysql_query($sqlgetSchemeNoDistWise);
$arrCountSource=mysql_fetch_row($querygetSchemeNoDistWise);
return $arrCountSource[0];
//echo $sqlgetSchemeNoDistWise;
}

/*function getHpNo($distId,$blockId)
{
	$sqlgetHpNo="SELECT sum(hp_no) FROM `tbl_dtls_q2_main` main,tbl_dtls_q2_habit hab WHERE hab.q2_id=main.id and district_id=".$distId." and block_id=".$blockId;
$querygetHpNo=mysql_query($sqlgetHpNo);
$arrCountHpSource=mysql_fetch_row($querygetHpNo);
return $arrCountHpSource[0];

}*/

function getTubeOpenWell($distId,$source,$curstatus,$block)
{
$q4="select count(b.current_status) from tbl_dtls_q1_main a,tbl_dtls_q1_sws b where a.id=b.loc_id and b.source='$source' and b.current_status='$curstatus' and a.district_id='$distId' and a.block_id='$block'" ;
$r4=mysql_query($q4);
$x=mysql_fetch_row($r4);
return $x[0];
}

function getHpNo($hp,$distId,$blockId)
{
	$sqlgetHpNo="SELECT sum($hp) FROM `tbl_dtls_q1_main` WHERE district_id=".$distId." and block_id=".$blockId;
$querygetHpNo=mysql_query($sqlgetHpNo);
$arrCountHpSource=mysql_fetch_row($querygetHpNo);
return $arrCountHpSource[0];

}

?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Block</title>
</head>
<body>
<table border="0" width="631" cellspacing="0" cellpadding="0">
	<tr>
		<td width="631" height="56" bgcolor="#E9E9E9">
		<p align="center"><span style="font-size: 9pt; font-weight: 700">
		<font face="Verdana" color="#224568">Block wise Source details and their status (as per PHED)</font></span>
        <div align="center"><span style="font-size: 9pt; font-weight: 700"><font face="Verdana" color="#224568">Table 14</font></span></div>
      </td>
	</tr>
	<tr>
		<td bgcolor="#E9E9E9" height="56">
		<table border="1" width="629" cellspacing="0" cellpadding="0" height="217" bgcolor="#C5D8EB">
			<tr>
				<td width="118" height="60" align="center">
				<font style="font-size: 8.5pt" face="Verdana">Name of Block</font></td>
				<td width="126" align="center">
				<p align="center"><font face="Verdana" style="font-size: 8.5pt">
			  Type of Sources</font></td>
				<td width="140" align="center">
				<font style="font-size: 8.5pt" face="Verdana">Total number of sources</font></td>
				
				<td width="108" align="center">
				<font face="Verdana" style="font-size: 8.5pt">Functional<font color="#FF0000"></font></font></td>
                <td width="125" align="center">
				<font face="Verdana" style="font-size: 8.5pt">Non Functional</font></td>
            </tr>
			
			<?php
			
			while($rowReport = mysql_fetch_array($queryReport)) {
			/*if(($rowReport['district_id']==389) || ($rowReport['district_id']==390) || ($rowReport['district_id']==391) || ($rowReport['district_id']==392) || ($rowReport['district_id']==401) || ($rowReport['district_id']==402) || ($rowReport['district_id']==403) || ($rowReport['district_id']==404) || ($rowReport['district_id']==405) || ($rowReport['district_id']==406) || ($rowReport['district_id']==416))
			{
			$lpcd=70;
			}else{
			$lpcd=40;
			}
			$no_hp=getTotalFunctionalStatusNoBlockWise($distId,$rowReport['block_id']);
			$current_pop_hp=getPopulationSchemeBlockWise($distId,'HP',$rowReport['block_id']);
			$water_demand_hp=number_format(($current_pop_hp*$lpcd)/1000,2,'.','');
			$design_pop_hp=round(getDesignPopWater('DP_population',$distId,$rowReport['block_id']));
			$design_water_hp=getDesignPopWater('DP_water_demand',$distId,$rowReport['block_id']);
			
			
			$CurrentPopulation=getSourcesBasedHP('present_population','Open-Well',$rowReport['block_id']);
			$CurrentWaterDemand=number_format(($CurrentPopulation*$lpcd)/1000,2,'.','');
			$CurrentPopulation1=getSourcesBasedHP('present_population','Tube-Well',$rowReport['block_id']);
			$CurrentWaterDemand1=number_format(($CurrentPopulation1*$lpcd)/1000,2,'.','');
			$a=getSources('Open-Well',$rowReport['block_id']);
			$b=getSources('Tube-Well',$rowReport['block_id']);
			$c=getSourcesBasedHP('hp_nos','Open-Well',$rowReport['block_id']);
			$d=getSourcesBasedHP('hp_nos','Tube-Well',$rowReport['block_id']);
			$e=getSourcesBasedHP('sp_nos','Open-Well',$rowReport['block_id']);
			$f=getSourcesBasedHP('sp_nos','Tube-Well',$rowReport['block_id']);
			$g=round(getSourcesBasedHP('population','Open-Well',$rowReport['block_id']));
			$h=round(getSourcesBasedHP('population','Tube-Well',$rowReport['block_id']));
			$i=getSourcesBasedHP('water_demand','Open-Well',$rowReport['block_id']);
			$j=getSourcesBasedHP('water_demand','Tube-Well',$rowReport['block_id']);
			$k=getMaximumYeild('Open-Well',$rowReport['block_id']);
			$l=getMaximumYeild('Tube-Well',$rowReport['block_id']);
			$Total1=$a+$b+$no_hp;
			$Total2=$c+$d;
			$Total3=$e+$f;
			$Total4=$g+$h+$design_pop_hp;
			$Total5=$i+$j+$design_water_hp;
			$Total6=$CurrentPopulation+$CurrentPopulation1+$current_pop_hp;
			$Total7=$CurrentWaterDemand+$CurrentWaterDemand1+$water_demand_hp;
			$Total8=$k+$l;*/
			//echo getTubeOpenWellSource($rowReport['block_id'],'Open-Well','','defunct');
			$funcow=getTubeOpenWell($distId,'Open-Well','operation',$rowReport['block_id']);
			$nfuncow=getTubeOpenWell($distId,'Open-Well','defunct',$rowReport['block_id']);
			$funtw=getTubeOpenWell($distId,'Tube-Well','operation',$rowReport['block_id']);
			$nfunctw=getTubeOpenWell($distId,'Tube-Well','defunct',$rowReport['block_id']);
			$funchp=getFunctionalStatusNoBlockWise($distId,'FUNCTIONAL',$rowReport['block_id']);
			$nfunchp=getNotFunctionalNoBlockWise($distId,'Repairable',$rowReport['block_id'])+getTotalNotRepairable($rowReport['block_id'],'Repairable');
			
			?>
			
			<tr bgcolor="#FFFFFF">
			  <td width="118" rowspan="5" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $rowReport['block_name'];?></font></td>
				
				<td width="126" height="21" align="center"><font style="font-size: 8.5pt" face="Verdana"> OW</font></td>
				<td width="140" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $totow=$funcow+$nfuncow;?></font></td>
				
				
				<td width="108" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $funcow;?></font></td>
                <td width="125" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $nfuncow;?></font></td>
          </tr>
			<tr bgcolor="#FFFFFF">
			  <td height="23" align="center"><font style="font-size: 8.5pt" face="Verdana">TW</font></td>
		      <td width="140" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $tottw=$funtw+$nfunctw;?></font></td>
		      <td width="108" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $funtw;?></font></td>
		      
		      <td width="125" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $nfunctw;?></font></td>
		      
		  </tr>
		  <tr bgcolor="#FFFFFF">
			  <td height="23" align="center"><font style="font-size: 8.5pt" face="Verdana">HP(Q2)</font></td>
		      <td width="140" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $totfunchp=$funchp+$nfunchp;?></font></td>
		      <td width="108" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $funchp;?></font></td>
		      
		      <td width="125" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $nfunchp;?></font></td>
		      
		  </tr>
		   <tr bgcolor="#FFFFFF">
			  <td height="23" align="center"><font style="font-size: 8.5pt" face="Verdana">HP(Q1)</font></td>
		      <td width="140" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $hpnos=getHpNo('hp_nos',$distId,$rowReport['block_id']);?></font></td>
		      <td width="108" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php //echo $d;?></font></td>
		      
		      <td width="125" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php //echo $water_demand_hp;?></font></td>
		      
		  </tr>
		  <tr bgcolor="#FFFFFF">
			  <td height="23" align="center"><font style="font-size: 8.5pt" face="Verdana">SP(Q1)</font></td>
		      <td width="140" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $spnos=getHpNo('sp_nos',$distId,$rowReport['block_id']);?></font></td>
		      <td width="108" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php //echo $d;?></font></td>
		      
		      <td width="125" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php //echo $water_demand_hp;?></font></td>
		      
		  </tr>
			
			<tr bgcolor="#E9E9E9">
				<td width="118" align="center"><font style="font-size: 8.5pt" face="Verdana">Total</font></td>
				<td align="center" width="126"><font style="font-size: 8.5pt" face="Verdana">&nbsp;</font></td>
				<td align="center" width="140"><font style="font-size: 8.5pt" face="Verdana"><?php echo $Total1=$totow+$tottw+$totfunchp+$hpnos+$spnos;?></font></td>
				
				<td align="center" width="108"><font style="font-size: 8.5pt" face="Verdana"><?php echo $Total2=$funcow+$funtw+$funchp;?></font></td>
                <td align="center" width="125"><font style="font-size: 8.5pt" face="Verdana"><?php echo $Total3=$nfuncow+$nfunctw+$nfunchp;?></font></td>
            </tr>
            <?php
			$GrandTotal1+=$Total1;
			$GrandTotal2+=$Total2;
			$GrandTotal3+=$Total3;
			//$GrandTotal4+=$Total4;
			//$GrandTotal5+=$Total5;
			//$GrandTotal6+=$Total6;
			//$GrandTotal7+=$Total7;
			//$GrandTotal8+=$Total8;
			}
			?>
            <tr bgcolor="#E9E9E9">
				<td width="118" align="center"><font style="font-size: 8.5pt" face="Verdana">Grand Total</font></td>
				<td align="center" width="126"><font style="font-size: 8.5pt" face="Verdana">&nbsp;</font></td>
				<td align="center" width="140"><font style="font-size: 8.5pt" face="Verdana"><?php echo $GrandTotal1;?></font></td>
				
				<td align="center" width="108"><font style="font-size: 8.5pt" face="Verdana"><?php echo $GrandTotal2;?></font></td>
                <td align="center" width="125"><font style="font-size: 8.5pt" face="Verdana"><?php echo $GrandTotal3;?></font></td>
            </tr>
		</table>
	  </td>
	</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

</body>

</html>

